<template>
  <div class="app-container">
    <!-- 空气报警设定 -->
    <!-- 查找  v-permission="['alarmSet:airAlarm:read']"
    添加  v-permission="['alarmSet:airAlarm:create']"
    编辑  v-permission="['alarmSet:airAlarm:update']"
    删除  v-permission="['alarmSet:airAlarm:delete']"
    添加人员  v-permission="['alarmSet:airAlarm:create']"
    添加教室  v-permission="['alarmSet:airAlarm:create']" -->
    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline filter">
      <el-form-item v-if="this.$store.state.user.fsiteLevel==3"  label="市/区/学校">
        <el-select disabled v-model="listQuery.fsiteNo" clearable filterable class="filter-item" placeholder="请选择市/区/学校">
        <el-option
          v-for="item in fsiteNoBelongOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      </el-form-item>
      <el-form-item v-else label="市/区/学校">
        <el-select v-model="listQuery.fsiteNo" clearable filterable class="filter-item" placeholder="请选择市/区/学校">
        <el-option
          v-for="item in fsiteNoBelongOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      </el-form-item>
      <el-form-item label="项目名称">
        <el-select v-model="listQuery.fairitem" clearable filterable class="filter-item" placeholder="请选择项目名称">
        <el-option
          v-for="item in sTsAiritemOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      </el-form-item>
      <el-form-item>
        <el-button round size="medium" class="filter-item" :style="{background:buttonColor.lookup,color:buttonColor.color}" @click="handleFilter">查找</el-button>
      <el-button round size="medium" class="filter-item" :style="{background:buttonColor.add ,color:buttonColor.color}" @click="handleCreate">添加</el-button>
      </el-form-item>
      </el-form>

    <!-- 查询结果 -->
    <el-table :height="buttonColor.clientHeight" v-loading="listLoading" :data="list" :header-cell-style="tableColor" element-loading-text="正在查询中。。。" border fit highlight-current-row>
       <el-table-column align="center" :width="buttonColor.operationTwo" label="操作" class-name="small-padding">
        <template slot-scope="scope">
           <div class="operationButton">
            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="handleUpdate(scope.row)">
            <img src="../../../public/images/edit.png" />
            编辑
          </div>
          <div :style="{color:buttonColor.delete,cursor:'pointer'}" @click="handleDelete(scope.row)">
            <img src="../../../public/images/del.png" />
            删除
          </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.line" :index="indexMethod" align="center" label="序" type="index"/>
      <el-table-column :formatter="formatSite" align="left" label="学校名称" prop="fsiteNo"/>
      <el-table-column :width="buttonColor.state" align="left" label="统计范围" prop="fscoreFlag">
        <template slot-scope="scope">
          <span :style="{color:buttonColor.provinceColor}" v-if="scope.row.fscoreFlag===1">{{ scope.row.fscoreFlag | flagFilter }}</span>
          <span :style="{color:buttonColor.cityColor}" v-else>{{ scope.row.fscoreFlag | flagFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="formatSTsAiritem" align="left" label="项目名称" prop="fairitem"/>
      <el-table-column width="80" align="left" label="起始值" prop="fbegnum"/>
      <el-table-column width="80" align="left" label="结束值" prop="fendnum"/>
      <el-table-column align="left" label="报警说明" prop="fdescribe"/>
      <el-table-column :formatter="formatflevelno" align="left" label="风险等级" prop="flevelno" />
      <el-table-column :width="buttonColor.state" align="left" label="发送短信" prop="fsendmsg">
        <template slot-scope="scope">
          <span :style="{color:buttonColor.statedisable}" v-if="scope.row.fsendmsg==0">{{ scope.row.fsendmsg | sendStatusFilter }}</span>
          <span :style="{color:buttonColor.statestart}" v-else>{{ scope.row.fsendmsg | sendStatusFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.state" align="left" label="发送邮件" prop="fsendemail">
         <template slot-scope="scope">
          <span :style="{color:buttonColor.statedisable}" v-if="scope.row.fsendemail==0">{{ scope.row.fsendemail | sendStatusFilter }}</span>
          <span :style="{color:buttonColor.statestart}" v-else>{{ scope.row.fsendemail | sendStatusFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.state" align="left" label="设定状态" prop="fstate">
        <template slot-scope="scope">
          <span :style="{color:buttonColor.statedisable}" v-if="scope.row.fstate==0">{{ scope.row.fstate | statusFilter }}</span>
          <span :style="{color:buttonColor.statestart}" v-else>{{ scope.row.fstate | statusFilter }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog width="auto" top="0vh" :close-on-click-modal="false" :visible.sync="dialogFormVisible">
      <template slot="title">
      <div :style="titleColor">{{textMap[dialogStatus]}}</div>
    </template>
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="auto">
        <el-row>
          <el-col :span="8">
            <el-form-item label="学校名称" prop="fsiteNo">
              <el-select v-model="dataForm.fsiteNo" clearable filterable placeholder="请选择">
                <el-option
                  v-for="item in fsiteNoBelongOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="统计范围" prop="fscoreFlag">
              <el-select :disabled="fscoreFlagStatus || dialogStatus==='update'" v-model="dataForm.fscoreFlag" class="filter-item" placeholder="请选择统计范围" @change="changeFscoreFlag2(dataForm.fscoreFlag)">
                <el-option v-for="(key, value) in flagMap" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
          </el-col>
         <el-col :span="8">
           <el-form-item label="设定状态" prop="fstate">
              <el-select v-model="dataForm.fstate" class="filter-item" placeholder="请选择状态">
                <el-option v-for="(key, value) in statusMap" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
         </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="空气项目名称" prop="fairitem">
              <el-select v-model="dataForm.fairitem" clearable filterable placeholder="请选择" @change="changeFscoreFlag(dataForm.fairitem)">
                <el-option
                  v-for="item in sTsAiritemOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="起始值" prop="fbegnum">
              <el-input v-model="dataForm.fbegnum"/>
            </el-form-item>
          </el-col>
         <el-col :span="8">
           <el-form-item label="结束值" prop="fendnum">
              <el-input v-model="dataForm.fendnum"/>
            </el-form-item>
         </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="报警说明" prop="fdescribe">
              <el-input v-model="dataForm.fdescribe"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否发送邮件" prop="fsendemail">
              <el-select v-model="dataForm.fsendemail" class="filter-item" placeholder="请选择状态">
                <el-option v-for="(key, value) in sendStatusMap2" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
          </el-col>
         <el-col :span="8">
            <el-form-item label="是否发送短信" prop="fsendmsg">
              <el-select v-model="dataForm.fsendmsg" class="filter-item" placeholder="请选择状态">
                <el-option v-for="(key, value) in sendStatusMap2" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
         </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="风险等级" prop="flevelno">
              <el-select clearable filterable v-model="dataForm.flevelno" class="filter-item" placeholder="请选择状态">
                <el-option
                v-for="item in getListAreas"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card">
        <el-tab-pane label="人员列表">
          <div class="filter-container">
            <el-button round size="medium" class="filter-item" :style="{background:buttonColor.add ,color:buttonColor.color}" icon="el-icon-edit" @click="handleUpdate1(dataForm.fsiteNo)">添加人员</el-button><!--handleCreate-->
            <el-table height="20vh" v-loading="listLoading" :data="dataForm.atsUsers" :header-cell-style="tableColor" element-loading-text="正在查询中。。。" border fit highlight-current-row>

              <el-table-column :index="indexMethod" align="center" label="序" type="index"/>
              <el-table-column align="center" label="人员名称" prop="username"/>
              <el-table-column align="center" width="140" label="操作" class-name="small-padding">
                <template slot-scope="scope">
                  <el-button :style="{background:buttonColor.delete,color:buttonColor.color}" round size="small" @click="handleDelete1(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="教室列表">
          <div v-show="dataForm.fscoreFlag === '2'" class="filter-container">
            <el-button round size="medium" class="filter-item" :style="{background:buttonColor.add ,color:buttonColor.color}" icon="el-icon-edit" @click="handleUpdate2(dataForm.fsiteNo)">添加教室</el-button>
            <el-table height="20vh" v-loading="listLoading" :data="dataForm.atsPoints" :header-cell-style="tableColor" element-loading-text="正在查询中。。。" border fit highlight-current-row>
              <el-table-column :index="indexMethod" align="center" label="序" type="index"/>
              <el-table-column align="center" label="教室名称" prop="fpointName"/>
              <el-table-column align="center" width="140" label="操作" class-name="small-padding">
                <template slot-scope="scope">
                  <el-button :style="{background:buttonColor.delete,color:buttonColor.color}" round size="small" @click="handleDelete2(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="cancel()">取消</el-button>
        <el-button v-if="dialogStatus=='create'" :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="createData">确定</el-button>
        <el-button v-else :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="updateData">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible1">
      <template slot="title">
      <div :style="titleColor">{{textMap[dialogStatus]}}</div>
    </template>
      <el-form ref="dataForm1" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="110px" style="width: 630px; margin-left:50px;">
        <el-table ref="multipleTable" :data="atsUsers" tooltip-effect="dark" style="width: 100%;height:400px;overflow-y: auto;overflow-x: hidden" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"/>
          <el-table-column prop="fuserno" label="人员编号" width="120"/>
          <el-table-column prop="username" label="人员名称" show-overflow-tooltip/>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible1 = false">取消</el-button>
        <el-button :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="addData">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible2">
      <template slot="title">
      <div :style="titleColor">{{textMap[dialogStatus]}}</div>
    </template>
      <el-form ref="dataForm2" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="110px" style="width: 630px; margin-left:50px;">
        <el-table ref="multipleTable" :data="atsPoints" tooltip-effect="dark" style="width: 100%;height:400px;overflow-y: auto;overflow-x: hidden" @selection-change="handleSelectionChange2">
          <el-table-column type="selection" width="55"/>
          <el-table-column prop="fpointNo" label="教室编号" width="120"/>
          <el-table-column prop="fpointName" label="教室名称" show-overflow-tooltip/>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible2 = false">取消</el-button>
        <el-button :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="addData2">确定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listAirAlarm, createAirAlarm, updateAirAlarm, deleteAirAlarm, listPointByFsiteNo, listUserByFsiteNo, sTsAiritemOptions } from '@/api/airAlarm'
import { fsiteOptionsByLevel,getListArea } from '@/api/area' // fsiteNoBelongOptions
import Pagination from '@/components/Pagination'
import moment from 'moment/moment'
import { tableColor,titleColor,buttonColor } from '@/filters/index'

const statusMap = {
  0: '停止',
  1: '启用'
}

const flagMap = {
  1: '学校',
  2: '教室'
}

// const sendStatusMap = {
//   0: '未发送',
//   1: '已发送'
// }

const sendStatusMap2 = {
  0: '否',
  1: '是'
}

export default {
  name: 'AirAlarm',
  components: { Pagination },
  filters: {
    statusFilter(type) {
      return statusMap[type]
    },
    flagFilter(type) {
      return flagMap[type]
    },
    sendStatusFilter(type) {
      return sendStatusMap2[type]
    }
  },
  data() {
    return {
      getListAreas:null,
      multipleSelection: [],
      multipleSelection2: [],
      multiple: [],
      multiple2: [],
      atsUsersTmp: [],
      atsPointsTmp: [],
      list: null,
      total: 0,
      fsiteNoBelongOptions: null,
      sTsAiritemOptions: null,
      fscoreFlagStatus: false,
      // fscoreFlagStatus2: false,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        fairitem: undefined,
        sort: 'create_time',
        order: 'desc'
      },
      statusMap,
      flagMap,
      // sendStatusMap,
      sendStatusMap2,
      dataForm: {
        id: undefined,
        fwarringno: undefined,
        fsiteNo: undefined,
        fscoreFlag: undefined,
        fairitem: undefined,
        fbegnum: undefined,
        fendnum: undefined,
        fdescribe: undefined,
        fsendmsg: undefined,
        flevelno: undefined,
        fsendemail: undefined,
        fstate: undefined,
        atsUsers: [],
        atsPoints: []
      },
      atsUsers: null,
      atsPoints: null,
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogStatus: '',
      dialogStatus1: '',
      dialogStatus2: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      tableColor: tableColor,
      titleColor: titleColor,
      buttonColor:buttonColor,
      rules: {
        fsiteNo: [
          { required: true, message: '学校名称不能为空', trigger: 'blur' }
        ],
        fscoreFlag: [
          { required: true, message: '统计范围不能为空', trigger: 'blur' }
        ],
        fairitem: [
          { required: true, message: '空气项目名称不能为空', trigger: 'blur' }
        ],
        fbegnum: [
          { required: true, message: '起始值不能为空', trigger: 'blur' }
        ],
        fendnum: [
          { required: true, message: '结束值不能为空', trigger: 'blur' }
        ],
        fdescribe: [
          { required: true, message: '报警说明不能为空', trigger: 'blur' }
        ],
        fsendmsg: [
          { required: true, message: '是否发送短信不能为空', trigger: 'blur' }
        ],
        flevelno: [
          { required: true, message: '风险等级不能为空', trigger: 'blur' }
        ],
        fsendemail: [
          { required: true, message: '是否发送邮件不能为空', trigger: 'blur' }
        ],
        fstate: [
          { required: true, message: '设定状态不能为空', trigger: 'blur' }
        ]
      },
      permissionDialogFormVisible: false,
      systemPermissions: null,
      assignedPermissions: null,
      permissionForm: {
        roleId: undefined,
        permIds: []
      }
    }
  },
  created() {
    if(this.$store.state.user.fsiteLevel==3) {
      this.listQuery.fsiteNo = this.$store.state.user.fsiteNo
    }
    this.getList()
    fsiteOptionsByLevel(3) // fsiteNoBelongOptions(2)
      .then(response => {
        this.fsiteNoBelongOptions = response.data.data.list
      })
      .catch(() => {
        this.fsiteNoBelongOptions = []
      })
    sTsAiritemOptions()
      .then(response => {
        this.sTsAiritemOptions = response.data.data.list
      })
      .catch(() => {
        this.sTsAiritemOptions = []
      })
      getListArea({flag:7})
      .then(response => {
        this.getListAreas = response.data.data.list
      })
      .catch(() => {
        this.getListAreas = []
      })
  },
  methods: {
    formatflevelno: function(row, column) {
      if(this.getListAreas){
        for (let i = 0; i < this.getListAreas.length; i++) {
        if (row.flevelno === this.getListAreas[i].value) {
          return this.getListAreas[i].label
        }
      }
      return ''
      }else{
      return ''
      }

    },

    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSelectionChange2(val) {
      this.multipleSelection2 = val
    },
    formatStatus: function(row, column) {
      return row.fsiteState === 1 ? '启用' : '禁用'
    },
    dateFormat(row, column) {
      const date = row[column.property]
      if (date === undefined) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    formatSite: function(row, column) {
      if(this.fsiteNoBelongOptions){
         for (let i = 0; i < this.fsiteNoBelongOptions.length; i++) {
        if (row.fsiteNo === this.fsiteNoBelongOptions[i].value) {
          return this.fsiteNoBelongOptions[i].label
        }
      }
      return ''
      }else{
        return ''
      }
    },
    formatSTsAiritem: function(row, column) {
      if(this.sTsAiritemOptions){
        for (let i = 0; i < this.sTsAiritemOptions.length; i++) {
        if (row.fairitem === this.sTsAiritemOptions[i].value) {
          return this.sTsAiritemOptions[i].label
        }
      }
      return ''
      }else{
        return ''
      }
    },
    getList() {
      this.listLoading = true
      listAirAlarm(this.listQuery)
        .then(response => {
          this.list = response.data.data.list
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        id: undefined,
        fwarringno: undefined,
        fsiteNo: undefined,
        fscoreFlag: undefined,
        fairitem: undefined,
        fbegnum: undefined,
        fendnum: undefined,
        fdescribe: undefined,
        fsendmsg: undefined,
        flevelno: undefined,
        fsendemail: undefined,
        fstate: undefined,
        atsUsers: [],
        atsPoints: []
      }
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    createData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          createAirAlarm(this.dataForm)
            .then(response => {
              this.list.unshift(response.data.data)
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '添加空气报警设定成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.data.msg
              })
            })
        }
      })
    },
    cancel() {
      this.dialogFormVisible = false
      // for (var i in this.multiple) {
      //   var atsUser = this.multiple[i]
      //   for (var j in this.dataForm.atsUsers) {
      //     if (atsUser.fuserno === this.dataForm.atsUsers[j].fuserno) {
      //       this.dataForm.atsUsers.splice(j)
      //       break
      //     }
      //   }
      // }
      this.multiple = []
      // for (var m in this.multiple2) {
      //   var atsPoint = this.multiple2[m]
      //   for (var n in this.dataForm.atsPoints) {
      //     if (atsPoint.fpointNo === this.dataForm.atsPoints[n].fpointNo) {
      //       this.dataForm.atsPoints.splice(n)
      //       break
      //     }
      //   }
      // }
      this.multiple2 = []
      this.list.forEach(v => {
        if (v.fwarringno === this.dataForm.fwarringno) {
          this.dataForm.atsUsers = this.atsUsersTmp
          this.dataForm.atsPoints = this.atsPointsTmp
          const index = this.list.indexOf(v)
          this.list.splice(index, 1, this.dataForm)
          return
        }
      })
    },
    addData() {
      this.dialogFormVisible1 = false
      for (var i in this.multipleSelection) {
        var atsUser = this.multipleSelection[i]
        var canAdd = true
        for (var j in this.dataForm.atsUsers) {
          if (atsUser.fuserno + '' === this.dataForm.atsUsers[j].fuserno) {
            canAdd = false
            break
          }
        }
        if (canAdd) {
          atsUser.fwarringno = this.dataForm.fwarringno
          this.dataForm.atsUsers.push(atsUser)
          this.multiple.push(atsUser)
        }
      }
    },
    addData2() {
      this.dialogFormVisible2 = false
      for (var i in this.multipleSelection2) {
        var atsPoint = this.multipleSelection2[i]
        var canAdd = true
        for (var j in this.dataForm.atsPoints) {
          if (atsPoint.fpointNo === this.dataForm.atsPoints[j].fpointNo) {
            canAdd = false
            break
          }
        }
        if (canAdd) {
          atsPoint.fwarringno = this.dataForm.fwarringno
          this.dataForm.atsPoints.push(atsPoint)
          this.multiple2.push(atsPoint)
        }
      }
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row)
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.dataForm.fscoreFlag = row.fscoreFlag.toString()
      this.dataForm.fstate = row.fstate.toString()
      this.dataForm.fsendmsg = row.fsendmsg.toString()
      this.dataForm.fsendemail = row.fsendemail.toString()
      this.atsUsersTmp = []
      this.atsPointsTmp = []
      row.atsUsers.forEach(v => {
        this.atsUsersTmp.push(v)
      })
      row.atsPoints.forEach(v => {
        this.atsPointsTmp.push(v)
      })
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    handleUpdate1(fsiteNo) {
      if (fsiteNo == null) {
        this.$notify.info({
          title: '',
          message: '请先选择学校'
        })
        return
      }
      listUserByFsiteNo(fsiteNo)
        .then(response => {
          this.atsUsers = response.data.data.list
        })
        .catch(() => {
          this.atsUsers = []
        })
      this.dialogStatus1 = 'update'
      this.dialogFormVisible1 = true
      this.multipleSelection = []
      this.$nextTick(() => {
        this.$refs['dataForm1'].clearValidate()
      })
    },
    handleUpdate2(fsiteNo) {
      if (fsiteNo == null) {
        this.$notify.info({
          title: '',
          message: '请先选择学校'
        })
        return
      }
      listPointByFsiteNo(fsiteNo)
        .then(response => {
          this.atsPoints = response.data.data.list
        })
      this.dialogStatus2 = 'update'
      this.dialogFormVisible2 = true
      this.multipleSelection2 = []
      this.$nextTick(() => {
        this.$refs['dataForm2'].clearValidate()
      })
    },
    updateData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          updateAirAlarm(this.dataForm)
            .then(() => {
              for (const v of this.list) {
                if (v.fwarringno === this.dataForm.fwarringno) {
                  const index = this.list.indexOf(v)
                  this.dataForm.fstate=parseInt(this.dataForm.fstate)
                  this.dataForm.fsendmsg=parseInt(this.dataForm.fsendmsg)
                  this.dataForm.fsendemail=parseInt(this.dataForm.fsendemail)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新管理员成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.data.msg
              })
            })
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除该空气报警设定', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteAirAlarm(row)
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除空气报警设定成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.data.msg
            })
          })
      })
    },
    handleDelete1(row) {
      this.dataForm.atsUsers.pop(row)
    },
    handleDelete2(row) {
      this.dataForm.atsPoints.pop(row)
    },
    indexMethod(index) {
      index = index + 1
      return index
    },
    changeFscoreFlag(fairitem) {
      if (fairitem.toString().substring(0, 1) === '1') { // 室外
        this.dataForm.fscoreFlag = '1' // 学校
        this.fscoreFlagStatus = true
      } else {
        this.fscoreFlagStatus = false
      }
    },
    changeFscoreFlag2(fscoreFlag) {
      if (fscoreFlag === '1') { // 学校
        this.dataForm.atsPoints = []
      //   this.fscoreFlagStatus2 = false
      // } else {
      //   this.fscoreFlagStatus2 = true
      }
    }
  }
}
</script>
